package com.simple.common.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

/**
 * @author yasud
 * @date 2020年07月21日 14:09
 * @description
 */
@Data
public class ResData<T> {

    /**
     * code
     */
    private int code;

    /**
     * 描述
     */
    private String msg;

    /**
     * 数据
     */
    private T data;

    /**
     * 正常状态
     * @param data
     * @return
     */
    public static <T> ResData ok(T data) {
        ResData resData = new ResData();
        resData.code = 200;
        resData.data = data;
        resData.msg = "success";
        return resData;
    }

    @JsonIgnore
    public boolean isOk(){
        if (code==200) {
            return true;
        }
        return false;
    }

    /**
     * 正常状态
     * @return
     */
    public static ResData ok() {
        ResData resData = new ResData();
        resData.code = 200;
        resData.data = null;
        resData.msg = "success";
        return resData;
    }

    /**
     * 错误状态
     * @param msg
     * @return
     */
    public static ResData error(String msg) {
        ResData resData = new ResData();
        resData.code = 500;
        resData.data = null;
        resData.msg = msg;
        return resData;
    }

    /**
     * 错误状态
     * @param code
     * @param msg
     * @return
     */
    public static ResData error(int code, String msg) {
        ResData resData = new ResData();
        resData.code = code;
        resData.data = null;
        resData.msg = msg;
        return resData;
    }
}
